#include<bits/stdc++.h>
using namespace std;
const int MAXN=500001;
int n,q,p;
int a[MAXN];
bool check(int x,int y,int a,int b){
	return (x*a+y)%p==b;
}
int solve(int x,int y){
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i,k=i;1<=j&&k<=n;j--,k++){
			if(!check(x,y,a[j],a[k]))break;
			if(!check(x,y,a[k],a[j]))break;
			ans++;
		}
	}
	for(int i=1;i<n;i++){
		for(int j=i,k=i+1;1<=j&&k<=n;j--,k++){
			if(!check(x,y,a[j],a[k]))break;
			if(!check(x,y,a[k],a[j]))break;
			ans++;
		}
	}
	return ans;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
	cin>>n>>q>>p;
	for(int i=1;i<=n;i++)cin>>a[i];
	while(q--){
		int op,x,y;
		cin>>op;
		int ans=0;
		if(op==1){
			cin>>x;
			for(y=0;y<p;y++)ans+=solve(x,y);
		}
		else{
			cin>>y;
			for(x=0;x<p;x++)ans+=solve(x,y);
		}
		cout<<ans<<'\n';
	}
	return 0;
}
